package UIFree.graphicTools.color
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.geom.Point;
	
	public class uif_frameColorCtrl extends uif_baseColorCtrl {
		private var _posField: uif_ecomponent;
		public function uif_frameColorCtrl(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}
		
		override protected function createComponents():void {
			super.createComponents();
			_posField = new uif_ecomponent(palette, 0, 0, frameSize.x, frameSize.y, style.posField);
		}
		
		protected function get frameSize(): Point {
			return new Point(palette.stepSize, palette.stepSize);
		}
		
		override protected function doClick(e: Event):void {
			super.doClick(e);
			setFramePos(palette.mouseX, palette.mouseY);
		}
		
		protected function setFramePos(ax: Number, ay: Number): void {
			_posField.position = calcFramePos(ax, ay);
		}
		
		protected function calcFramePos(aX: Number, aY: Number): Point {
			return new Point(Math.floor(aX / palette.stepSize) * palette.stepSize,
						Math.floor(aY / palette.stepSize) * palette.stepSize);
		}
	}
}